

//数据菜单切换
//笛卡尔点
$("#locations").on('click',function(){
	$("#io_locations").css('display','block').siblings().css('display','none');
	$("#locations").addClass('active_li').siblings().removeClass('active_li');
});
//关节点
$("#joints").on('click',function(){
	$("#io_joints").css('display','block').siblings().css('display','none');
	$("#joints").addClass('active_li').siblings().removeClass('active_li');
});
//整数
$("#longs").on('click',function(){
	$("#io_longs").css('display','block').siblings().css('display','none');
	$("#longs").addClass('active_li').siblings().removeClass('active_li');
});
//小数
$("#doubles").on('click',function(){
	$("#io_doubles").css('display','block').siblings().css('display','none');
	$("#doubles").addClass('active_li').siblings().removeClass('active_li');
});
//字符串
$("#strings").on('click',function(){
	$("#io_strings").css('display','block').siblings().css('display','none');
	$("#strings").addClass('active_li').siblings().removeClass('active_li');
});
//视觉
$("#visions").on('click',function(){
	$("#io_visions").css('display','block').siblings().css('display','none');
	$("#visions").addClass('active_li').siblings().removeClass('active_li');
});


//新增笛卡尔点
//弹出新增笛卡尔点的对话框
$(".addLocations").on('click',function(){
	$("#addLocationsMask").css('display','block');
	darg(document.getElementById("addLocationsModal"));
});
//关闭新增笛卡尔点的对话框
$("#closeLocationsModal").on('click',function(){
	$("#addLocationsMask").css('display','none');
});
//确定新增笛卡尔点
$("#srueLocationsModal").on('click',function(){
	
	$li=$('<li class="locationsContent_li"></li>');
	
	$span0=$('<span class="locationsContent_span0"></span>');
	$span0.html($(".addLocations_input0").val());
	if($(".addLocations_input0").val()==''){
		$span0.html('JP01');
	}
	$li.append($span0);
	
	$span1=$('<span class="locationsContent_span1"></span>');
	$span1.html($(".addLocations_input1").val());
	if($(".addLocations_input1").val()==''){
		$span1.html('0.00');
	}
	$li.append($span1);
	
	$span2=$('<span class="locationsContent_span2"></span>');
	$span2.html($(".addLocations_input2").val());
	if($(".addLocations_input2").val()==''){
		$span2.html('0.00');
	}
	$li.append($span2);
	
	$span3=$('<span class="locationsContent_span3"></span>');
	$span3.html($(".addLocations_input3").val());
	if($(".addLocations_input3").val()==''){
		$span3.html('0.00');
	}
	$li.append($span3);
	
	$span4=$('<span class="locationsContent_span4"></span>');
	$span4.html($(".addLocations_input4").val());
	if($(".addLocations_input4").val()==''){
		$span4.html('0.00');
	}
	$li.append($span4);
	
	$span5=$('<span class="locationsContent_span5"></span>');
	$span5.html($(".addLocations_input5").val());
	if($(".addLocations_input5").val()==''){
		$span5.html('0.00');
	}
	$li.append($span5);
	
	$span6=$('<span class="locationsContent_span6"></span>');
	$span6.html($(".addLocations_input6").val());
	if($(".addLocations_input6").val()==''){
		$span6.html('0.00');
	}
	$li.append($span6);
	
	$span7=$('<span class="locationsContent_span7"></span>');
	$li.append($span7);
	
	$span8=$('<span class="locationsContent_span8"><input type="checkbox" class="locationsCheckeds"></span>');
	$li.append($span8);
	
	$("#locationsContent_ul").append($li);
	
	var mInput=document.getElementById("addLocationsModal").getElementsByTagName("input");
	for(var i=0;i<mInput.length;i++){
		mInput[i].value='';
	}
	
	$("#addLocationsMask").css('display','none');
	
});

//全选中笛卡尔点位
var locationsFlag=true;
var allLocationsChecked=document.getElementsByClassName("locationsCheckeds");
$("#clickLocationsChecked").on('click',function(){
	if(locationsFlag==true){
		document.getElementById("locationsChecked").checked=true;
		for(var i=0;i<allLocationsChecked.length;i++){
			allLocationsChecked[i].checked =true;
		}
		locationsFlag=false;
	}else{
		document.getElementById("locationsChecked").checked=false;
		for(var i=0;i<allLocationsChecked.length;i++){
			allLocationsChecked[i].checked =false;
		}
		locationsFlag=true;
	}
	
});
//删除全部笛卡尔点位
$(".removeLocations").on('click',function(){
	for(var i=allLocationsChecked.length-1;i>=0;i--){
		if(allLocationsChecked[i].checked == true){
			allLocationsChecked[i].parentNode.parentNode.remove();
		}
	}
	document.getElementById("locationsChecked").checked=false;
	locationsFlag=true;
});

//修改笛卡尔点
var locationsUl=document.getElementById("locationsContent_ul");
var aInputs=document.getElementById("modifyLocationsModal").getElementsByTagName("input");
var aSpan;
locationsUl.onclick=function(ev){
	ev=ev||window.event;
	aSpan=ev.target||ev.srcElement;//兼容不同的浏览器的事件源
	if(aSpan.className=='locationsContent_span7'){
		document.getElementById("modifyLocationsMask").style.display="block";
		darg(document.getElementById("modifyLocationsModal"));
		var aSpans=aSpan.parentNode.childNodes;
		for(var i=0;i<7;i++){
			aInputs[i].value=aSpans[i].innerHTML;
		}
	}
}
//关闭修改笛卡尔点的对话框
document.getElementById("closeLocationsModify").onclick=function(){	
	document.getElementById("modifyLocationsMask").style.display="none";
}
//确定修改的笛卡尔点位
document.getElementById("srueLocationsModify").onclick=function(){
	var aSpans=aSpan.parentNode.childNodes;
	for(var i=0;i<7;i++){
		aSpans[i].innerHTML=aInputs[i].value;
	}
	document.getElementById("modifyLocationsMask").style.display="none";
}



//新增关节点
//弹出新增关节点的对话框
$(".addJoints").on('click',function(){
	//$("#addJointsMask").css('display','block');
	$("#addJointsMask").fadeIn(500);
	darg(document.getElementById("addJointsModal"));
});
//关闭新增关节点的对话框
$("#closeJointsModal").on('click',function(){
	//$("#addJointsMask").css('display','none');
	$("#addJointsMask").fadeOut(500);
});
//确定新增关节点
$("#srueJointsModal").on('click',function(){
	
	$li=$('<li class="jointsContent_li"></li>');
	
	$span0=$('<span class="jointsContent_span0"></span>');
	$span0.html($(".addJoints_input0").val());
	if($(".addJoints_input0").val()==''){
		$span0.html('JP01');
	}
	$li.append($span0);
	
	$span1=$('<span class="jointsContent_span1"></span>');
	$span1.html($(".addJoints_input1").val());
	if($(".addJoints_input1").val()==''){
		$span1.html('0.00');
	}
	$li.append($span1);
	
	$span2=$('<span class="jointsContent_span2"></span>');
	$span2.html($(".addJoints_input2").val());
	if($(".addJoints_input2").val()==''){
		$span2.html('0.00');
	}
	$li.append($span2);
	
	$span3=$('<span class="jointsContent_span3"></span>');
	$span3.html($(".addJoints_input3").val());
	if($(".addJoints_input3").val()==''){
		$span3.html('0.00');
	}
	$li.append($span3);
	
	$span4=$('<span class="jointsContent_span4"></span>');
	$span4.html($(".addJoints_input4").val());
	if($(".addJoints_input4").val()==''){
		$span4.html('0.00');
	}
	$li.append($span4);
	
	$span5=$('<span class="jointsContent_span5"></span>');
	$span5.html($(".addJoints_input5").val());
	if($(".addJoints_input5").val()==''){
		$span5.html('0.00');
	}
	$li.append($span5);
	
	$span6=$('<span class="jointsContent_span6"></span>');
	$span6.html($(".addJoints_input6").val());
	if($(".addJoints_input6").val()==''){
		$span6.html('0.00');
	}
	$li.append($span6);
	
	$span7=$('<span class="jointsContent_span7"></span>');
	$span7.html($(".addJoints_input7").val());
	if($(".addJoints_input7").val()==''){
		$span7.html('0.00');
	}
	$li.append($span7);
	
	$span8=$('<span class="jointsContent_span8"></span>');
	$li.append($span8);
	
	$span9=$('<span class="jointsContent_span9"><input type="checkbox" class="jointsCheckeds"></span>');
	$li.append($span9);
	
	$("#jointsContent_ul").append($li);
	
	var mInput=document.getElementById("addJointsModal").getElementsByTagName("input");
	for(var i=0;i<mInput.length;i++){
		mInput[i].value='';
	}
	
	//$("#addJointsMask").css('display','none');
	$("#addJointsMask").fadeOut(500);
});
//全选关节点
var jointsFlag=true;
var allJointsChecked=document.getElementsByClassName("jointsCheckeds");
$("#clickJointsChecked").on('click',function(){
	if(jointsFlag==true){
		document.getElementById("jointsChecked").checked=true;
		for(var i=0;i<allJointsChecked.length;i++){
			allJointsChecked[i].checked =true;
		}
		jointsFlag=false;
	}else{
		document.getElementById("jointsChecked").checked=false;
		for(var i=0;i<allJointsChecked.length;i++){
			allJointsChecked[i].checked =false;
		}
		jointsFlag=true;
	}
	
});
//删除全部关节点
$(".removeJoints").on('click',function(){
	for(var i=allJointsChecked.length-1;i>=0;i--){
		if(allJointsChecked[i].checked == true){
			allJointsChecked[i].parentNode.parentNode.remove();
		}
	}
	document.getElementById("jointsChecked").checked=false;
	jointsFlag=true;
});

//修改关节点
var jointsUl=document.getElementById("jointsContent_ul");
var bInputs=document.getElementById("modifyJointsModal").getElementsByTagName("input");
var bSpan;
jointsUl.onclick=function(ev){
	ev=ev||window.event;
	bSpan=ev.target||ev.srcElement;//兼容不同的浏览器的事件源
	if(bSpan.className=='jointsContent_span8'){
		document.getElementById("modifyJointsMask").style.display="block";
		darg(document.getElementById("modifyJointsModal"));
		var bSpans=bSpan.parentNode.childNodes;
		for(var i=0;i<8;i++){
			bInputs[i].value=bSpans[i].innerHTML;
		}
	}
}

//关闭修改关节点的对话框
document.getElementById("closeJointsModify").onclick=function(){	
	document.getElementById("modifyJointsMask").style.display="none";
}
//确定修改的关节点
document.getElementById("srueJointsModify").onclick=function(){
	var bSpans=bSpan.parentNode.childNodes;
	for(var i=0;i<8;i++){
		bSpans[i].innerHTML=bInputs[i].value;
	}

	document.getElementById("modifyJointsMask").style.display="none";
}



//新增整数
//弹出新增整数的对话框
$(".addLongs").on('click',function(){
	$("#addLongsMask").css('display','block');
	darg(document.getElementById("addLongsModal"));
});
//关闭新增整数的对话框
$("#closeLongsModal").on('click',function(){
	$("#addLongsMask").css('display','none');
});
//确定新增整数
$("#srueLongsModal").on('click',function(){
	
	$li=$('<li class="longsContent_li"></li>');
	
	$span0=$('<span class="longsContent_span0"></span>');
	$span0.html($(".addLongs_input0").val());
	if($(".addLongs_input0").val()==''){
		$span0.html('JP01');
	}
	$li.append($span0);
	
	$span1=$('<span class="longsContent_span1"></span>');
	$span1.html($(".addLongs_input1").val());
	if($(".addLongs_input1").val()==''){
		$span1.html('0.00');
	}
	$li.append($span1);
	
	$span2=$('<span class="longsContent_span2"></span>');
	$li.append($span2);
	
	$span3=$('<span class="longsContent_span3"><input type="checkbox" class="longsCheckeds"></span>');
	$li.append($span3);
	
	$("#longsContent_ul").append($li);
	
	var mInput=document.getElementById("addLongsModal").getElementsByTagName("input");
	for(var i=0;i<mInput.length;i++){
		mInput[i].value='';
	}
	
	$("#addLongsMask").css('display','none');
	
});
//全选整数
var longsFlag=true;
var allLongsChecked=document.getElementsByClassName("longsCheckeds");
$("#clickLongsChecked").on('click',function(){
	if(longsFlag==true){
		document.getElementById("longsChecked").checked=true;
		for(var i=0;i<allLongsChecked.length;i++){
			allLongsChecked[i].checked =true;
		}
		longsFlag=false;
	}else{
		document.getElementById("longsChecked").checked=false;
		for(var i=0;i<allLongsChecked.length;i++){
			allLongsChecked[i].checked =false;
		}
		longsFlag=true;
	}
	
});
//删除全部整数
$(".removeLongs").on('click',function(){
	for(var i=allLongsChecked.length-1;i>=0;i--){
		if(allLongsChecked[i].checked == true){
			allLongsChecked[i].parentNode.parentNode.remove();
		}
	}
	document.getElementById("longsChecked").checked=false;
	longsFlag=true;
});

//修改整数
var longsUl=document.getElementById("longsContent_ul");
var cInputs=document.getElementById("modifyLongsModal").getElementsByTagName("input");
var cSpan;
longsUl.onclick=function(ev){
	ev=ev||window.event;
	cSpan=ev.target||ev.srcElement;//兼容不同的浏览器的事件源
	if(cSpan.className=='longsContent_span2'){
		document.getElementById("modifyLongsMask").style.display="block";
		darg(document.getElementById("modifyLongsModal"));
		var cSpans=cSpan.parentNode.childNodes;
		for(var i=0;i<2;i++){
			cInputs[i].value=cSpans[i].innerHTML;
		}
	}
}

//关闭修改整数的对话框
document.getElementById("closeLongsModify").onclick=function(){	
	document.getElementById("modifyLongsMask").style.display="none";
}
//确定修改的整数
document.getElementById("srueLongsModify").onclick=function(){
	var cSpans=cSpan.parentNode.childNodes;
	for(var i=0;i<2;i++){
		cSpans[i].innerHTML=cInputs[i].value;
	}

	document.getElementById("modifyLongsMask").style.display="none";
}


//新增小数
//弹出新增小数的对话框
$(".addDoubles").on('click',function(){
	$("#addDoublesMask").css('display','block');
	darg(document.getElementById("addDoublesModal"));
});
//关闭新增小数的对话框
$("#closeDoublesModal").on('click',function(){
	$("#addDoublesMask").css('display','none');
});
//确定新增小数
$("#srueDoublesModal").on('click',function(){
	
	$li=$('<li class="doublesContent_li"></li>');
	
	$span0=$('<span class="doublesContent_span0"></span>');
	$span0.html($(".addDoubles_input0").val());
	if($(".addDoubles_input0").val()==''){
		$span0.html('JP01');
	}
	$li.append($span0);
	
	$span1=$('<span class="doublesContent_span1"></span>');
	$span1.html($(".addDoubles_input1").val());
	if($(".addDoubles_input1").val()==''){
		$span1.html('0.00');
	}
	$li.append($span1);
	
	$span2=$('<span class="doublesContent_span2"></span>');
	$li.append($span2);
	
	$span3=$('<span class="doublesContent_span3"><input type="checkbox" class="doublesCheckeds"></span>');
	$li.append($span3);
	
	$("#doublesContent_ul").append($li);
	
	var mInput=document.getElementById("addDoublesModal").getElementsByTagName("input");
	for(var i=0;i<mInput.length;i++){
		mInput[i].value='';
	}
	
	$("#addDoublesMask").css('display','none');
	
});
//全选小数
var doublesFlag=true;
var allDoublesChecked=document.getElementsByClassName("doublesCheckeds");
$("#clickDoublesChecked").on('click',function(){
	if(doublesFlag==true){
		document.getElementById("doublesChecked").checked=true;
		for(var i=0;i<allDoublesChecked.length;i++){
			allDoublesChecked[i].checked =true;
		}
		doublesFlag=false;
	}else{
		document.getElementById("doublesChecked").checked=false;
		for(var i=0;i<allDoublesChecked.length;i++){
			allDoublesChecked[i].checked =false;
		}
		doublesFlag=true;
	}
	
});
//删除全部小数
$(".removeDoubles").on('click',function(){
	for(var i=allDoublesChecked.length-1;i>=0;i--){
		if(allDoublesChecked[i].checked == true){
			allDoublesChecked[i].parentNode.parentNode.remove();
		}
	}
	document.getElementById("doublesChecked").checked=false;
	doublesFlag=true;
});

//修改小数
var doublesUl=document.getElementById("doublesContent_ul");
var dInputs=document.getElementById("modifyDoublesModal").getElementsByTagName("input");
var dSpan;
doublesUl.onclick=function(ev){
	ev=ev||window.event;
	dSpan=ev.target||ev.srcElement;//兼容不同的浏览器的事件源
	if(dSpan.className=='doublesContent_span2'){
		document.getElementById("modifyDoublesMask").style.display="block";
		darg(document.getElementById("modifyDoublesModal"));
		var dSpans=dSpan.parentNode.childNodes;
		for(var i=0;i<2;i++){
			dInputs[i].value=dSpans[i].innerHTML;
		}
	}
}

//关闭修改小数的对话框
document.getElementById("closeDoublesModify").onclick=function(){	
	document.getElementById("modifyDoublesMask").style.display="none";
}
//确定修改的小数
document.getElementById("srueDoublesModify").onclick=function(){
	var dSpans=dSpan.parentNode.childNodes;
	for(var i=0;i<2;i++){
		dSpans[i].innerHTML=dInputs[i].value;
	}

	document.getElementById("modifyDoublesMask").style.display="none";
}



//新增字符串
//弹出新增字符串的对话框
$(".addStrings").on('click',function(){
	$("#addStringsMask").css('display','block');
	darg(document.getElementById("addStringsModal"));
});
//关闭新增字符串的对话框
$("#closeStringsModal").on('click',function(){
	$("#addStringsMask").css('display','none');
});
//确定新增字符串
$("#srueStringsModal").on('click',function(){
	
	$li=$('<li class="stringsContent_li"></li>');
	
	$span0=$('<span class="stringsContent_span0"></span>');
	$span0.html($(".addStrings_input0").val());
	if($(".addStrings_input0").val()==''){
		$span0.html('JP01');
	}
	$li.append($span0);
	
	$span1=$('<span class="stringsContent_span1"></span>');
	$span1.html($(".addStrings_input1").val());
	if($(".addStrings_input1").val()==''){
		$span1.html('0.00');
	}
	$li.append($span1);
	
	$span2=$('<span class="stringsContent_span2"></span>');
	$li.append($span2);
	
	$span3=$('<span class="stringsContent_span3"><input type="checkbox" class="stringsCheckeds"></span>');
	$li.append($span3);
	
	$("#stringsContent_ul").append($li);
	
	var mInput=document.getElementById("addStringsModal").getElementsByTagName("input");
	for(var i=0;i<mInput.length;i++){
		mInput[i].value='';
	}
	
	$("#addStringsMask").css('display','none');
	
});
//全选字符串
var stringsFlag=true;
var allStringsChecked=document.getElementsByClassName("stringsCheckeds");
$("#clickStringsChecked").on('click',function(){
	if(doublesFlag==true){
		document.getElementById("stringsChecked").checked=true;
		for(var i=0;i<allStringsChecked.length;i++){
			allStringsChecked[i].checked =true;
		}
		stringsFlag=false;
	}else{
		document.getElementById("stringsChecked").checked=false;
		for(var i=0;i<allStringsChecked.length;i++){
			allStringsChecked[i].checked =false;
		}
		stringsFlag=true;
	}
	
});
//删除全部字符串
$(".removeStrings").on('click',function(){
	for(var i=allStringsChecked.length-1;i>=0;i--){
		if(allStringsChecked[i].checked == true){
			allStringsChecked[i].parentNode.parentNode.remove();
		}
	}
	document.getElementById("stringsChecked").checked=false;
	stringsFlag=true;
});

//修改字符串
var stringsUl=document.getElementById("stringsContent_ul");
var eInputs=document.getElementById("modifyStringsModal").getElementsByTagName("input");
var eSpan;
stringsUl.onclick=function(ev){
	ev=ev||window.event;
	eSpan=ev.target||ev.srcElement;//兼容不同的浏览器的事件源
	if(eSpan.className=='stringsContent_span2'){
		document.getElementById("modifyStringsMask").style.display="block";
		darg(document.getElementById("modifyStringsModal"));
		var eSpans=eSpan.parentNode.childNodes;
		for(var i=0;i<2;i++){
			eInputs[i].value=eSpans[i].innerHTML;
		}
	}
}

//关闭修改字符串的对话框
document.getElementById("closeStringsModify").onclick=function(){	
	document.getElementById("modifyStringsMask").style.display="none";
}
//确定修改的字符串
document.getElementById("srueStringsModify").onclick=function(){
	var eSpans=eSpan.parentNode.childNodes;
	for(var i=0;i<2;i++){
		eSpans[i].innerHTML=eInputs[i].value;
	}

	document.getElementById("modifyStringsMask").style.display="none";
}



//************ 弹出框的拖拽效果 ******************
//封装拖拽函数
function darg(obj){
	var oW, oH;
	// 绑定touchstart事件
	obj.addEventListener("touchstart", function(e) {
		var touches = e.touches[0];
		oW = touches.clientX - obj.offsetLeft;
		oH = touches.clientY - obj.offsetTop;
		//阻止页面的滑动默认事件
		document.addEventListener("touchmove", defaultEvent, false);
	}, false)
	obj.addEventListener("touchmove", function(e) {
		var touches = e.touches[0];
		var oLeft = touches.clientX - oW;
		var oTop = touches.clientY - oH;
		if(oLeft < 0) {
			oLeft = 0;
		} else if(oLeft > obj.parentNode.offsetWidth - obj.offsetWidth) {
			oLeft = (obj.parentNode.offsetWidth - obj.offsetWidth);
		}
		if(oTop < 0) {
			oTop = 0;
		} else if(oTop > obj.parentNode.offsetHeight - obj.offsetHeight) {
			oTop = (obj.parentNode.offsetHeight - obj.offsetHeight);
		}
		obj.style.left = oLeft + "px";
		obj.style.top = oTop + "px";
	}, false);
	
	obj.addEventListener("touchend", function() {
		document.removeEventListener("touchmove", defaultEvent, false);
	}, false);
	function defaultEvent(e) {
		//e.preventDefault();
	}
}
